﻿package plugin.shenlu
{
    import cmd.*;
    import com.core.*;
    import com.greensock.*;
    import com.sh.game.display.*;
    import com.sh.game.util.*;
    import flash.events.*;
    import manager.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import morn.core.utils.*;
    import plugin.shenlu.view.*;
    import pluginfw.nio.*;
    import uiresource.shenlu.*;

    public class ShenluUICtrl extends ShenluUI
    {
        private var MBlevelgonfig:Object;
        private var timeline:TweenMax;
        private var _instance:Shenlu;
        private var i:int;
        private var TileIndex:int;
        private var Message:Object;
        private var _shenlugonfig:Object;
        private var shenludataArr:Array;
        private var itemconfig:Object;
        public var shenlubuyView:ShenluBuyView;
        public var shenluzbview:ShenluZBView;
        private var shuxing_info:Array;
        private var _curwidthTab:int = 0;
        private var userLV:int;
        private var shuomingArr:Array;
        private var typearr:Array;
        private var xiaohaocount:int;
        private var yongyoucount:int;
        private var msgobj:Object;
        private var maxlv:int;

        public function ShenluUICtrl(param1:Shenlu)
        {
            this.MBlevelgonfig = ConfigDictionary.data.activitygoal;
            this._shenlugonfig = ConfigDictionary.data.shenlu;
            this.shenludataArr = [];
            this.itemconfig = ConfigDictionary.data.item;
            this.shuxing_info = [["血量上限: 0%"], ["物理防御: 0", "魔法防御: 0"], ["物理攻击: 0", "魔法攻击: 0", "道术攻击: 0"], ["暴    击: 0", "暴击伤害: 0"]];
            this.shuomingArr = ["血符说明:\n1，血符可以极大增加生命上限\n2，血符碎片可以通过参加活动、击杀boss等方式获得\n3，血符不可以进行强化", "护盾说明:\n1，护盾可以极大增加防御力\n2，护盾碎片可以通过参加活动、击杀boss、挂机、回收装备等方式获得\n3，护盾不可以进行强化", "宝石说明:\n1，宝石可以极大增加攻击力\n2，宝石碎片可以通过参加活动、击杀boss、商城购买等方式获得\n3，宝石不可以进行强化", "魂珠说明:\n1，魂珠可以极大增加暴击和暴击伤害\n2，魂珠碎片可以通过参加活动、击杀boss、商城购买等方式获得\n3，魂珠不可以进行强化"];
            this.typearr = [];
            this._instance = param1;
            closeBtn.clickHandler = new Handler(this._instance.close);
            return;
        }// end function

        public function get curwidthTab() : int
        {
            return this._curwidthTab;
        }// end function

        override protected function createChildren() : void
        {
            viewClassMap["uiresource.shenlu.ShenluBuyViewUI"] = ShenluBuyView;
            viewClassMap["uiresource.shenlu.ShenluZBViewUI"] = ShenluZBView;
            loadUI("Shenlu.xml");
            shenluyulanZBVI.visible = false;
            shenlubuyUIVI.visible = false;
            this.shenlubuyView = shenlubuyUIVI as ShenluBuyView;
            this.shenluzbview = shenluyulanZBVI as ShenluZBView;
            return;
        }// end function

        override protected function initializeView() : void
        {
            var _loc_2:Object = null;
            super.initializeView();
            var _loc_1:* = Control.create(ShenluControl, this);
            ModelProxy.addObserver("shenlu", _loc_1);
            this.typearr = [];
            this.typearr.push({bagcount:UserData.getBagData("atkchip"), _type:3});
            this.typearr.push({bagcount:UserData.getBagData("defchip"), _type:2});
            this.typearr.push({bagcount:UserData.getBagData("hpchip"), _type:1});
            this.typearr.push({bagcount:UserData.getBagData("crichip"), _type:4});
            this.shenludataArr = [];
            for each (_loc_2 in this._shenlugonfig)
            {
                
                this.shenludataArr.push(_loc_2);
            }
            if (this.TileIndex > 0)
            {
                this.Infoshow(this.TileIndex);
            }
            else
            {
                this.TileIndex = 1;
            }
            qitaLabel.addEventListener(MouseEvent.CLICK, this.OnConClickZB);
            goumaishuipianLabel.addEventListener(MouseEvent.CLICK, this.OnConClickBuy);
            shuomingLabel.addEventListener(MouseEvent.MOUSE_OVER, this.OnTips);
            yeqianTab.selectHandler = new Handler(this.onConClicktile);
            upBtn.addEventListener(MouseEvent.CLICK, this.OnpuBtnClick);
            return;
        }// end function

        private function closefaliang() : void
        {
            upBtn.disabled = true;
            if (this.timeline)
            {
                this.timeline.kill();
            }
            upBtn.filters = [];
            if (upBtn.disabled)
            {
                ObjectUtils.gray(upBtn);
            }
            return;
        }// end function

        private function faliang() : void
        {
            upBtn.disabled = false;
            if (this.timeline)
            {
                this.timeline.kill();
            }
            upBtn.filters = [];
            this.timeline = TweenMax.to(upBtn, 1, {glowFilter:{color:16763904, alpha:1, blurX:6, blurY:6, strength:4}, repeat:int.MAX_VALUE, yoyo:true});
            return;
        }// end function

        protected function OnTips(event:MouseEvent) : void
        {
            ModelProxy.change("tips", "normal", "<font color=\'#31cf08\'>" + this.shuomingArr[(this.TileIndex - 1)] + "</font>");
            shuomingLabel.addEventListener(MouseEvent.MOUSE_OUT, this.closeTips);
            return;
        }// end function

        protected function closeTips(event:MouseEvent) : void
        {
            ModelProxy.change("tips", "state", "close");
            shuomingLabel.removeEventListener(MouseEvent.MOUSE_OUT, this.closeTips);
            return;
        }// end function

        public function getinfo() : void
        {
            return;
        }// end function

        public function updateatkchipMSG(param1:int) : void
        {
            this.typearr[0].bagcount = param1;
            if (this.visible)
            {
                this.Infoshow(this.TileIndex);
            }
            return;
        }// end function

        public function updatedefchipMSG(param1:int) : void
        {
            this.typearr[1].bagcount = param1;
            if (this.visible)
            {
                this.Infoshow(this.TileIndex);
            }
            return;
        }// end function

        public function updatehpchipMSG(param1:int) : void
        {
            this.typearr[2].bagcount = param1;
            if (this.visible)
            {
                this.Infoshow(this.TileIndex);
            }
            return;
        }// end function

        public function updatecrichipMSG(param1:int) : void
        {
            this.typearr[3].bagcount = param1;
            if (this.visible)
            {
                this.Infoshow(this.TileIndex);
            }
            return;
        }// end function

        protected function OnConClickZB(event:MouseEvent) : void
        {
            shenluyulanZBVI.visible = true;
            shenlubuyUIVI.visible = false;
            this._curwidthTab = 272;
            this.zhuanbei();
            return;
        }// end function

        protected function OnConClickBuy(event:MouseEvent) : void
        {
            shenluyulanZBVI.visible = false;
            shenlubuyUIVI.visible = true;
            this.goumai();
            return;
        }// end function

        public function openRefresh() : void
        {
            var _loc_4:int = 0;
            this.userLV = UserData.getUserData("level");
            var _loc_1:* = UserData.getOnlineData();
            this.Message = _loc_1.armhc;
            var _loc_2:Object = {};
            var _loc_3:int = 0;
            while (_loc_3 < this.typearr.length)
            {
                
                _loc_4 = this.Message[this.typearr[_loc_3]._type];
                _loc_2 = this.Messagedata(this.typearr[_loc_3]._type);
                if (_loc_2[0].count != 1)
                {
                    _loc_2[0].xuyaoCL_count = _loc_2[0].count;
                }
                if (this.typearr[_loc_3].bagcount >= _loc_2[0].xuyaoCL_count && this.userLV >= _loc_2[0].uselv)
                {
                    if (_loc_4 >= this.maxlv)
                    {
                        this["titleBox_" + this.typearr[_loc_3]._type].visible = false;
                    }
                    else
                    {
                        this["titleBox_" + this.typearr[_loc_3]._type].visible = true;
                    }
                }
                else
                {
                    this["titleBox_" + this.typearr[_loc_3]._type].visible = false;
                }
                _loc_3++;
            }
            this.Infoshow(this.TileIndex);
            return;
        }// end function

        public function shuaxinYB() : void
        {
            this.shenlubuyView.shuaxinyb();
            return;
        }// end function

        private function onConClicktile(param1:int) : void
        {
            yeqianTab.selectedIndex = param1;
            this.TileIndex = param1 + 1;
            this.Infoshow(this.TileIndex);
            return;
        }// end function

        private function goumai() : void
        {
            var _loc_1:Array = null;
            var _loc_2:Array = null;
            if (shenlubuyUIVI.visible)
            {
                _loc_1 = [[219, 220, 221], [216, 217, 218], [214, 215], [417, 223, 224]];
                _loc_2 = _loc_1[(this.TileIndex - 1)];
                this.shenlubuyView.shopdatashow(_loc_2);
            }
            return;
        }// end function

        private function zhuanbei() : void
        {
            var _loc_2:Array = null;
            var _loc_3:Object = null;
            var _loc_4:Object = null;
            var _loc_1:* = UserData.getOnlineData();
            this.Message = _loc_1.armhc;
            if (shenluyulanZBVI.visible)
            {
                _loc_2 = [];
                this.i = 0;
                while (this.i < this.shenludataArr.length)
                {
                    
                    if (this.TileIndex == this.shenludataArr[this.i].type)
                    {
                        _loc_4 = this.itemconfig[this.shenludataArr[this.i].newid];
                        _loc_4.lv = this.shenludataArr[this.i].lv;
                        _loc_2.push(_loc_4);
                    }
                    var _loc_5:String = this;
                    var _loc_6:* = this.i + 1;
                    _loc_5.i = _loc_6;
                }
                this.shenluzbview.showlist(_loc_2, this.Message[this.TileIndex]);
            }
            return;
        }// end function

        private function Infoshow(param1:int) : void
        {
            var _loc_2:Object = null;
            var _loc_3:Object = null;
            this.zhuanbei();
            switch(param1)
            {
                case 1:
                {
                    goumaishuipianLabel.visible = false;
                    shenlubuyUIVI.visible = false;
                    shuomingLabel.label = "血符说明";
                    xiaohaocountLabel.text = "消耗血符碎片";
                    yongyoucountLabel.text = "拥有血符碎片";
                    qitaLabel.label = "其他血符";
                    break;
                }
                case 2:
                {
                    goumaishuipianLabel.visible = false;
                    shenlubuyUIVI.visible = false;
                    shuomingLabel.label = "护盾说明";
                    xiaohaocountLabel.text = "消耗护盾碎片";
                    yongyoucountLabel.text = "拥有护盾碎片";
                    qitaLabel.label = "其他护盾";
                    break;
                }
                case 3:
                {
                    goumaishuipianLabel.visible = true;
                    this.goumai();
                    shuomingLabel.label = "宝石说明";
                    xiaohaocountLabel.text = "消耗宝石碎片";
                    yongyoucountLabel.text = "拥有宝石碎片";
                    qitaLabel.label = "其他宝石";
                    break;
                }
                case 4:
                {
                    goumaishuipianLabel.visible = true;
                    this.goumai();
                    shuomingLabel.label = "魂珠说明";
                    xiaohaocountLabel.text = "消耗魂珠碎片";
                    yongyoucountLabel.text = "拥有魂珠碎片";
                    qitaLabel.label = "其他魂珠";
                    break;
                }
                default:
                {
                    break;
                }
            }
            this.msgobj = this.Messagedata(param1);
            var _loc_4:* = this.Message[param1];
            _loc_3 = this.itemconfig[this.msgobj[0].newid];
            if (_loc_4 == 0)
            {
                this.xiaohaocount = this.msgobj[0].count;
                list.array = this.shuxing_info[(param1 - 1)];
                list.renderHandler = new Handler(this.listRender);
                list1.visible = true;
            }
            else
            {
                this.xiaohaocount = this.msgobj[0].xuyaoCL_count;
                _loc_2 = this.itemconfig[this.msgobj[0].mainid];
                if (_loc_4 == this.maxlv)
                {
                    list.array = this.getAttribute(_loc_3);
                    list1.visible = false;
                }
                else
                {
                    list.array = this.getAttribute(_loc_2);
                    list1.visible = true;
                }
                list.renderHandler = new Handler(this.listRender);
            }
            item.data = _loc_3;
            list1.array = this.getAttribute(_loc_3);
            list1.renderHandler = new Handler(this.list1Render);
            this.i = 0;
            while (this.i < this.typearr.length)
            {
                
                if (param1 == this.typearr[this.i]._type)
                {
                    this.yongyoucount = this.typearr[this.i].bagcount;
                    break;
                }
                var _loc_5:String = this;
                var _loc_6:* = this.i + 1;
                _loc_5.i = _loc_6;
            }
            xiaohaoLabel.text = String(this.xiaohaocount);
            yongyouLabel.text = String(this.yongyoucount);
            if (this.yongyoucount < this.xiaohaocount)
            {
                yongyouLabel.color = MColor.New56;
            }
            else
            {
                yongyouLabel.color = "0xffffff";
            }
            if (this.yongyoucount >= this.xiaohaocount && this.userLV >= this.msgobj[0].uselv)
            {
                if (_loc_4 >= this.maxlv)
                {
                    this["titleBox_" + param1].visible = false;
                }
                else
                {
                    this["titleBox_" + param1].visible = true;
                }
            }
            else
            {
                this["titleBox_" + param1].visible = false;
            }
            if (this["titleBox_" + param1].visible)
            {
                this.faliang();
            }
            else
            {
                this.closefaliang();
            }
            return;
        }// end function

        private function Messagedata(param1:int) : Array
        {
            var _loc_2:* = UserData.getOnlineData();
            this.Message = _loc_2.armhc;
            var _loc_3:Array = [];
            var _loc_4:* = this.Message[param1];
            this.i = 0;
            while (this.i < this.shenludataArr.length)
            {
                
                if (param1 == this.shenludataArr[this.i].type)
                {
                    this.maxlv = this.shenludataArr[this.i].lv;
                }
                var _loc_5:String = this;
                var _loc_6:* = this.i + 1;
                _loc_5.i = _loc_6;
            }
            this.i = 0;
            while (this.i < this.shenludataArr.length)
            {
                
                if (_loc_4 == 0)
                {
                    if (param1 == this.shenludataArr[this.i].type)
                    {
                        _loc_3.push(this.shenludataArr[this.i]);
                        break;
                    }
                }
                else if (param1 == this.shenludataArr[this.i].type && _loc_4 == this.shenludataArr[this.i].lv)
                {
                    if (_loc_4 == this.maxlv)
                    {
                        _loc_3.push(this.shenludataArr[this.i]);
                        break;
                    }
                    else
                    {
                        _loc_3.push(this.shenludataArr[(this.i + 1)]);
                        break;
                    }
                }
                var _loc_5:String = this;
                var _loc_6:* = this.i + 1;
                _loc_5.i = _loc_6;
            }
            return _loc_3;
        }// end function

        protected function OnpuBtnClick(event:MouseEvent) : void
        {
            var _loc_2:Object = null;
            var _loc_3:int = 0;
            var _loc_5:Object = null;
            var _loc_6:int = 0;
            var _loc_7:int = 0;
            var _loc_11:Object = null;
            var _loc_12:XMLMovieClip = null;
            var _loc_13:int = 0;
            var _loc_14:int = 0;
            var _loc_15:int = 0;
            var _loc_16:int = 0;
            var _loc_17:Object = null;
            if (this.yongyoucount < this.xiaohaocount)
            {
                WarningManager.show(29);
                return;
            }
            var _loc_4:* = ModelProxy.getValue("data", "arms");
            for each (_loc_2 in _loc_4)
            {
                
                if (_loc_2)
                {
                    if (_loc_2.itemid == this.msgobj[0].mainid)
                    {
                        _loc_3 = _loc_2.id;
                    }
                }
            }
            _loc_5 = UserData.getBagData();
            _loc_6 = _loc_5.maxcount;
            _loc_7 = 1;
            while (_loc_7 <= _loc_6)
            {
                
                _loc_11 = _loc_5[_loc_7];
                if (_loc_11 && _loc_11[0] > 0)
                {
                    if (_loc_11[4].itemid == this.msgobj[0].mainid)
                    {
                        _loc_3 = _loc_11[0];
                        break;
                    }
                }
                _loc_7++;
            }
            var _loc_8:* = new Output();
            new Output().writeVarInt(this.msgobj[0].mainid, false);
            _loc_8.writeVarInt(_loc_3, false);
            PluginManager.instance.sendToBufferServer("shenlu", CMDShenlu.Getinfo, _loc_8);
            if (this.yongyoucount >= this.xiaohaocount && this.userLV >= this.msgobj[0].uselv)
            {
                _loc_12 = XMLMcManager.instance.getPluginMc("shenlu", "guanwei");
                if (_loc_12)
                {
                    this.addChild(_loc_12);
                    _loc_12.x = -60;
                    _loc_12.y = -205;
                    _loc_12.mouseChildren = false;
                    _loc_12.mouseEnabled = false;
                    _loc_12.playFromTo(0, (_loc_12.totalFrame - 1), new Handler(this.clipCompleteHandler, [_loc_12]));
                }
            }
            var _loc_9:Boolean = false;
            var _loc_10:* = ModelProxy.getValue("data", "jingjitypedata");
            if (ModelProxy.getValue("data", "jingjitypedata") == null)
            {
                return;
            }
            if (this.TileIndex == 3)
            {
                if (_loc_10[6])
                {
                    _loc_13 = this.Message[this.TileIndex];
                    for each (_loc_2 in this.MBlevelgonfig[6])
                    {
                        
                        _loc_14 = _loc_14 + 1;
                        if (_loc_10[6][0][(_loc_14 - 1)].isGet == 0 && _loc_13 >= _loc_2.goal && _loc_10[6][0][(_loc_14 - 1)].count < _loc_2.count)
                        {
                            _loc_9 = true;
                            ModelProxy.change("mainui", "showEffect", {ab:"kaifujingji", state:_loc_9});
                            break;
                        }
                    }
                }
            }
            if (this.TileIndex == 4)
            {
                if (_loc_10[7])
                {
                    _loc_15 = this.Message[this.TileIndex];
                    for each (_loc_17 in this.MBlevelgonfig[7])
                    {
                        
                        _loc_16 = _loc_16 + 1;
                        if (_loc_10[7][0][(_loc_16 - 1)].isGet == 0 && _loc_15 >= _loc_17.goal && _loc_10[7][0][(_loc_16 - 1)].count < _loc_17.count)
                        {
                            _loc_9 = true;
                            ModelProxy.change("mainui", "showEffect", {ab:"kaifujingji", state:_loc_9});
                            break;
                        }
                    }
                }
            }
            return;
        }// end function

        protected function clipCompleteHandler(param1:XMLMovieClip) : void
        {
            if (param1)
            {
                if (param1.parent)
                {
                    param1.parent.removeChild(param1);
                }
                param1.stop();
            }
            return;
        }// end function

        private function list1Render(param1:Component, param2:int) : void
        {
            var _loc_3:Array = null;
            var _loc_4:Label = null;
            var _loc_5:Label = null;
            if (param2 < list1.length)
            {
                _loc_3 = String(list1.array[param2]).split(":");
                _loc_4 = param1.getChildByName("shuxingLabel") as Label;
                _loc_4.text = _loc_3[0] + ":";
                _loc_5 = param1.getChildByName("numLabel") as Label;
                _loc_5.text = _loc_3[1];
            }
            return;
        }// end function

        private function listRender(param1:Component, param2:int) : void
        {
            var _loc_3:Array = null;
            var _loc_4:Label = null;
            var _loc_5:Label = null;
            if (param2 < list.length)
            {
                _loc_3 = String(list.array[param2]).split(":");
                _loc_4 = param1.getChildByName("shuxingLabel") as Label;
                _loc_4.text = _loc_3[0] + ":";
                _loc_5 = param1.getChildByName("numLabel") as Label;
                _loc_5.text = _loc_3[1];
            }
            return;
        }// end function

        public function getAttribute(param1:Object) : Array
        {
            var _loc_2:Array = [];
            if (param1.phyAttMax > 0)
            {
                _loc_2.push("物理攻击:" + param1.phyAtt + " - " + param1.phyAttMax);
            }
            if (param1.magicAttMax > 0)
            {
                _loc_2.push("魔法攻击:" + param1.magicAtt + " - " + param1.magicAttMax);
            }
            if (param1.taoAttMax > 0)
            {
                _loc_2.push("道术攻击:" + param1.taoAtt + " - " + param1.taoAttMax);
            }
            if (param1.pureatk > 0)
            {
                _loc_2.push("混乱攻击:" + param1.pureatk);
            }
            if (param1.phyDefMax > 0)
            {
                _loc_2.push("物理防御:" + param1.phyDef + " - " + param1.phyDefMax);
            }
            if (param1.magicDefMax > 0)
            {
                _loc_2.push("魔法防御:" + param1.magicDef + " - " + param1.magicDefMax);
            }
            if (param1.puredef > 0)
            {
                _loc_2.push("混乱防御:" + param1.puredef);
            }
            if (param1.hp > 0)
            {
                _loc_2.push("生命上限:" + param1.hp / 100 + "%");
            }
            if (param1.mp > 0)
            {
                _loc_2.push("魔法上限:" + param1.mp);
            }
            if (param1.luck > 0)
            {
                _loc_2.push("幸    运:" + param1.luck);
            }
            if (param1.critical > 0)
            {
                _loc_2.push("暴    击:" + param1.critical);
            }
            if (param1.critdmg > 0)
            {
                _loc_2.push("暴击伤害:" + param1.critdmg);
            }
            else if (param1.critRate)
            {
                _loc_2.push("暴击伤害:" + param1.critRate / 100 + "%");
            }
            if (param1.attackSpeed > 0)
            {
                _loc_2.push("攻击速度:" + param1.attackSpeed);
            }
            if (param1.pvpatk > 0)
            {
                _loc_2.push("对玩家伤害:" + param1.pvpatk / 100 + "%");
            }
            if (param1.pvpdef > 0)
            {
                _loc_2.push("对玩家免伤:" + param1.pvpdef / 100 + "%");
            }
            return _loc_2;
        }// end function

    }
}
